#include "Choose.h"
#include "SnakeWorld.h"
#include "SnakeWorld2.h"
#include "SnakeWorld3.h"
#include "Menu.h"
#include "cocos2d.h"
using namespace cocos2d;

CCScene* Choose::scene()
{
	CCScene *scene = NULL;
	do
	{
		scene = CCScene::create();
		CC_BREAK_IF(!scene);
		Choose *layer = Choose::create();
		CC_BREAK_IF(!layer);
		scene->addChild(layer);
	} while (0);
	return scene;
}

bool Choose::init()
{
	bool bRet = false;
	do
	{
		CC_BREAK_IF(!CCLayer::init());

		CCSize size = CCDirector::sharedDirector()->getWinSize();

		CCSprite * mu = CCSprite::create("Choose.jpg");
		CC_BREAK_IF(!mu);
		mu->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height/2));
		this->addChild(mu,0);

		CCLabelTTF *phurdle1 = CCLabelTTF::create("HURDLE1","Segoe Marker",24);
		CC_BREAK_IF(!phurdle1);

		CCLabelTTF *phurdle2 = CCLabelTTF::create("HURDLE2","Segoe Marker",24);
		CC_BREAK_IF(!phurdle2);

		CCLabelTTF *phurdle3 = CCLabelTTF::create("HURDLE3","Segoe Marker",24);
		CC_BREAK_IF(!phurdle3);

		CCLabelTTF *pBack = CCLabelTTF::create("BACK","Segoe Marker",24);
		CC_BREAK_IF(!pBack);

		CCMenuItemLabel *phurdle1Item = CCMenuItemLabel::create(phurdle1,this,menu_selector(Choose::Hurdle1));
		CC_BREAK_IF(!phurdle1Item);
		phurdle1Item->setPosition(ccp(size.width/2 + 60,size.height/2 + 30));

		CCMenuItemLabel *phurdle2Item = CCMenuItemLabel::create(phurdle2,this,menu_selector(Choose::Hurdle2));
		CC_BREAK_IF(!phurdle2Item);
		phurdle2Item->setPosition(ccp(size.width/2 + 60,size.height/2 - 10));

		CCMenuItemLabel *phurdle3Item = CCMenuItemLabel::create(phurdle3,this,menu_selector(Choose::Hurdle3));
		CC_BREAK_IF(!phurdle3Item);
		phurdle3Item->setPosition(ccp(size.width/2 + 60,size.height/2 - 50));

		CCMenuItemLabel *pBackItem = CCMenuItemLabel::create(pBack,this,menu_selector(Choose::goBack));
		CC_BREAK_IF(!pBackItem);
		pBackItem->setPosition(ccp(size.width/2 + 60,size.height/2 - 90));

		CCMenu *Ch = CCMenu::create(phurdle1Item,phurdle2Item,phurdle3Item,pBackItem,NULL);
		Ch->setPosition(CCPointZero);
		CC_BREAK_IF(!Ch);
		this->addChild(Ch,1);


		bRet = true;
	} while (0);
	return bRet;
}

void Choose::Hurdle1(CCObject* p)
{
	CCScene *s = SnakeWorld::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1,s));
}


void Choose::goBack(CCObject* pSender)
{
	CCScene *s = Menu::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1,s));
}

void Choose::Hurdle2(CCObject* pSender)
{
	CCScene *s = SnakeWorld2::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1,s));

}

void Choose::Hurdle3(CCObject* pSender)
{
	CCScene *s = SnakeWorld3::scene();
	CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1,s));

}